﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CTOOLS
{
    public partial class LoadForm : Form
    {
        BackgroundWorker Worker = null;
        public LoadForm(ref BackgroundWorker worker,int _Maximum)
        {
            InitializeComponent();
            Worker = worker;
            progressBar1.Maximum = _Maximum;//设置范围最大值
            Worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
            Worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
        }

        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Worker.ProgressChanged -= worker_ProgressChanged;
            this.Close();
        }

        void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            label1.Text=e.UserState.ToString();
            progressBar1.Value = e.ProgressPercentage;
        }

        //工作完成后执行的事件  
        public void OnProcessCompleted(object sender, EventArgs e)
        {
            this.Close();
        }

        //public void SetStatus(string msg)
        //{
        //    if (this.label1.InvokeRequired)
        //        this.label1.Invoke(new Action<string>(SetStatus), msg);
        //    else
        //        this.label1.Text = msg;
        //}

        //public void SetProgress(int value)
        //{
        //    if (this.progressBar1.InvokeRequired)
        //        this.label1.Invoke(new Action<int>(SetProgress), value);
        //    else
        //        this.progressBar1.Value = value < 0 ? 0 : value > 100 ? 100 : value;

        //    // if (value == 100) this.Invoke(new Action(this.Hide));

        //    this.Refresh();
        //}

    }
}
